home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 127 / PC Guia 127.iso / Software / Produtividade / OpenOffice.org 2.0.1 / openofficeorg2.cab / wordml2ooo_text.xsl < prev    next >
Extensible Markup Language  |  2005-09-10  |  63KB  |  1,062 lines

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3.  
  4.     OpenOffice.org - a multi-platform office productivity suite
  5.  
  6.     $RCSfile: wordml2ooo_text.xsl,v $
  7.  
  8.     $Revision: 1.9 $
  9.  
  10.     last change: $Author: rt $ $Date: 2005/09/08 22:13:34 $
  11.  
  12.     The Contents of this file are made available subject to
  13.     the terms of GNU Lesser General Public License Version 2.1.
  14.  
  15.  
  16.       GNU Lesser General Public License Version 2.1
  17.       =============================================
  18.       Copyright 2005 by Sun Microsystems, Inc.
  19.       901 San Antonio Road, Palo Alto, CA 94303, USA
  20.  
  21.       This library is free software; you can redistribute it and/or
  22.       modify it under the terms of the GNU Lesser General Public
  23.       License version 2.1, as published by the Free Software Foundation.
  24.  
  25.       This library is distributed in the hope that it will be useful,
  26.       but WITHOUT ANY WARRANTY; without even the implied warranty of
  27.       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  28.       Lesser General Public License for more details.
  29.  
  30.       You should have received a copy of the GNU Lesser General Public
  31.       License along with this library; if not, write to the Free Software
  32.       Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  33.       MA  02111-1307  USA
  34.  
  35. -->
  36. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml" xmlns:wx="http://schemas.microsoft.com/office/word/2003/auxHint" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:aml="http://schemas.microsoft.com/aml/2001/core" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events" exclude-result-prefixes="w wx aml o dt  v">
  37.     <xsl:template name="create-default-paragraph-styles">
  38.         <xsl:variable name="default-paragraph-style" select="w:style[@w:default = 'on' and @w:type = 'paragraph']"/>
  39.         <xsl:if test="$default-paragraph-style">
  40.             <style:default-style style:family="paragraph">
  41.                 <style:paragraph-properties>
  42.                     <xsl:attribute name="style:tab-stop-distance">
  43.                         <xsl:call-template name="ConvertMeasure">
  44.                             <xsl:with-param name="value" select="concat(/w:wordDocument/w:docPr/w:defaultTabStop/@w:val,'twip')"/>
  45.                         </xsl:call-template>cm</xsl:attribute>
  46.                 </style:paragraph-properties>
  47.                 <style:text-properties style:use-window-font-color="true">
  48.                     <xsl:choose>
  49.                         <xsl:when test="/w:wordDocument/w:fonts/w:defaultFonts">
  50.                             <xsl:attribute name="style:font-name">
  51.                                 <xsl:value-of select="/w:wordDocument/w:fonts/w:defaultFonts/@w:ascii"/>
  52.                             </xsl:attribute>
  53.                             <xsl:attribute name="style:font-name-asian">
  54.                                 <xsl:value-of select="/w:wordDocument/w:fonts/w:defaultFonts/@w:fareast"/>
  55.                             </xsl:attribute>
  56.                             <xsl:attribute name="style:font-name-complex">
  57.                                 <xsl:value-of select="/w:wordDocument/w:fonts/w:defaultFonts/@w:cs"/>
  58.                             </xsl:attribute>
  59.                         </xsl:when>
  60.                         <xsl:otherwise>
  61.                             <xsl:attribute name="style:font-name">Times New Roman</xsl:attribute>
  62.                         </xsl:otherwise>
  63.                     </xsl:choose>
  64.                     <xsl:if test="$default-paragraph-style/w:rPr/w:sz">
  65.                         <xsl:attribute name="fo:font-size">
  66.                             <xsl:value-of select="translate($default-paragraph-style/w:rPr/w:sz/@w:val,'Na','0') div 2"/>pt</xsl:attribute>
  67.                         <xsl:attribute name="style:font-size-asian">
  68.                             <xsl:value-of select="translate($default-paragraph-style/w:rPr/w:sz/@w:val,'Na','0') div 2"/>pt</xsl:attribute>
  69.                     </xsl:if>
  70.                     <xsl:if test="$default-paragraph-style/w:rPr/w:sz-cs">
  71.                         <xsl:attribute name="style:font-size-complex">
  72.                             <xsl:value-of select="$default-paragraph-style/w:rPr/w:sz-cs/@w:val div 2"/>pt</xsl:attribute>
  73.                     </xsl:if>
  74.                     <!-- if not defined default font size in Word, make it out as 10pt. glu -->
  75.                     <xsl:if test="not($default-paragraph-style/w:rPr/w:sz or w:rPr/w:sz-cs)">
  76.                         <xsl:attribute name="fo:font-size">10pt</xsl:attribute>
  77.                         <xsl:attribute name="style:font-size-asian">10pt</xsl:attribute>
  78.                         <xsl:attribute name="style:font-size-complex">10pt</xsl:attribute>
  79.                     </xsl:if>
  80.                     <xsl:if test="$default-paragraph-style/w:rPr/w:lang">
  81.                         <xsl:if test="$default-paragraph-style/w:rPr/w:lang/@w:val">
  82.                             <xsl:attribute name="fo:language">
  83.                                 <xsl:choose>
  84.                                     <xsl:when test="contains($default-paragraph-style/w:rPr/w:lang/@w:val, '-')">
  85.                                         <xsl:value-of select="substring-before( $default-paragraph-style/w:rPr/w:lang/@w:val, '-')"/>
  86.                                     </xsl:when>
  87.                                     <xsl:otherwise>
  88.                                         <xsl:value-of select="$default-paragraph-style/w:rPr/w:lang/@w:val"/>
  89.                                     </xsl:otherwise>
  90.                                 </xsl:choose>
  91.                                 <!--xsl:value-of select="substring-before( $default-paragraph-style/w:rPr/w:lang/@w:val, '-')"/ -->
  92.                             </xsl:attribute>
  93.                             <xsl:attribute name="fo:country">
  94.                                 <xsl:choose>
  95.                                     <xsl:when test="contains($default-paragraph-style/w:rPr/w:lang/@w:val, '-')">
  96.                                         <xsl:value-of select="substring-before( $default-paragraph-style/w:rPr/w:lang/@w:val, '-')"/>
  97.                                     </xsl:when>
  98.                                     <xsl:otherwise>
  99.                                         <xsl:value-of select="$default-paragraph-style/w:rPr/w:lang/@w:val"/>
  100.                                     </xsl:otherwise>
  101.                                 </xsl:choose>
  102.                                 <!--xsl:value-of select="substring-after( $default-paragraph-style/w:rPr/w:lang/@w:val, '-')"/-->
  103.                             </xsl:attribute>
  104.                         </xsl:if>
  105.                         <xsl:if test="$default-paragraph-style/w:rPr/w:lang/@w:fareast">
  106.                             <xsl:attribute name="style:language-asian">
  107.                                 <xsl:choose>
  108.                                     <xsl:when test="contains($default-paragraph-style/w:rPr/w:lang/@w:fareast, '-')">
  109.                                         <xsl:value-of select="substring-before( $default-paragraph-style/w:rPr/w:lang/@w:fareast, '-')"/>
  110.                                     </xsl:when>
  111.                                     <xsl:otherwise>
  112.                                         <xsl:value-of select="$default-paragraph-style/w:rPr/w:lang/@w:fareast"/>
  113.                                     </xsl:otherwise>
  114.                                 </xsl:choose>
  115.                                 <!--xsl:value-of select="substring-before( $default-paragraph-style/w:rPr/w:lang/@w:fareast, '-')"/-->
  116.                             </xsl:attribute>
  117.                             <xsl:attribute name="style:country-asian">
  118.                                 <xsl:choose>
  119.                                     <xsl:when test="contains($default-paragraph-style/w:rPr/w:lang/@w:fareast, '-')">
  120.                                         <xsl:value-of select="substring-before( $default-paragraph-style/w:rPr/w:lang/@w:fareast, '-')"/>
  121.                                     </xsl:when>
  122.                                     <xsl:otherwise>
  123.                                         <xsl:value-of select="$default-paragraph-style/w:rPr/w:lang/@w:fareast"/>
  124.                                     </xsl:otherwise>
  125.                                 </xsl:choose>
  126.                                 <!--xsl:value-of select="substring-after( $default-paragraph-style/w:rPr/w:lang/@w:fareast, '-')"/ -->
  127.                             </xsl:attribute>
  128.                         </xsl:if>
  129.                         <xsl:if test="$default-paragraph-style/w:rPr/w:lang/@w:bidi">
  130.                             <xsl:attribute name="style:language-complex">
  131.                                 <xsl:choose>
  132.                                     <xsl:when test="contains( $default-paragraph-style/w:rPr/w:lang/@w:bidi, '-') ">
  133.                                         <xsl:value-of select="substring-after( $default-paragraph-style/w:rPr/w:lang/@w:bidi, '-')"/>
  134.                                     </xsl:when>
  135.                                     <xsl:otherwise>
  136.                                         <xsl:value-of select="$default-paragraph-style/w:rPr/w:lang/@w:bidi "/>
  137.                                     </xsl:otherwise>
  138.                                 </xsl:choose>
  139.                                 <!--xsl:value-of select="substring-before( $default-paragraph-style/w:rPr/w:lang/@w:bidi, '-')"/-->
  140.                             </xsl:attribute>
  141.                             <xsl:attribute name="style:country-complex">
  142.                                 <xsl:choose>
  143.                                     <xsl:when test="contains($default-paragraph-style/w:rPr/w:lang/@w:bidi, '-')">
  144.                                         <xsl:value-of select="substring-after( $default-paragraph-style/w:rPr/w:lang/@w:bidi, '-')"/>
  145.                                     </xsl:when>
  146.                                     <xsl:otherwise>
  147.                                         <xsl:value-of select="$default-paragraph-style/w:rPr/w:lang/@w:bidi"/>
  148.                                     </xsl:otherwise>
  149.                                 </xsl:choose>
  150.                                 <!-- xsl:value-of select="substring-after( $default-paragraph-style/w:rPr/w:lang/@w:bidi, '-')"/ -->
  151.                             </xsl:attribute>
  152.                         </xsl:if>
  153.                     </xsl:if>
  154.                 </style:text-properties>
  155.             </style:default-style>
  156.         </xsl:if>
  157.     </xsl:template>
  158.     <xsl:template name="create-default-text-styles">
  159.         <style:style style:name="Footnote_20_Symbol" style:display-name="Footnote Symbol" style:family="text"/>
  160.         <style:style style:name="Numbering_20_Symbols" style:display-name="Numbering Symbols" style:family="text"/>
  161.         <style:style style:name="Bullet_20_Symbols" style:display-name="Bullet Symbols" style:family="text">
  162.             <style:text-properties style:font-name="StarSymbol" fo:font-size="9pt" style:font-name-asian="StarSymbol" style:font-size-asian="9pt" style:font-name-complex="StarSymbol" style:font-size-complex="9pt"/>
  163.         </style:style>
  164.         <style:style style:name="Endnote_20_Symbol" style:display-name="Endnote Symbol" style:family="text"/>
  165.         <style:style style:name="Footnote_20_anchor" style:display-name="Footnote anchor" style:family="text">
  166.             <style:text-properties style:text-position="super 58%"/>
  167.         </style:style>
  168.     </xsl:template>
  169.     <xsl:template match="w:p" mode="style">
  170.         <xsl:variable name="paragraph-number">
  171.             <xsl:number from="/w:wordDocument/w:body" level="any" count="w:p" format="1"/>
  172.         </xsl:variable>
  173.         <xsl:variable name="section-property-number" select="count(preceding::w:sectPr)"/>
  174.         <xsl:variable name="last-section-property" select="preceding::w:pPr/w:sectPr[1]"/>
  175.         <xsl:variable name="next-section-property" select="following::w:sectPr[1]"/>
  176.         <style:style style:family="paragraph" style:name="P{$paragraph-number}">
  177.             <xsl:if test="w:pPr/w:pStyle">
  178.                 <xsl:attribute name="style:parent-style-name">
  179.                     <xsl:value-of select="concat('w',translate(w:pPr/w:pStyle/@w:val,' ~`!@#$%^*(&)+/,;?<>{}[]:','_'))"/>
  180.                 </xsl:attribute>
  181.             </xsl:if>
  182.             <xsl:choose>
  183.                 <xsl:when test="not($next-section-property/w:type/@w:val = 'continuous') and  generate-id($last-section-property[last()]/following::w:p[1]) = generate-id(.) and not(ancestor::w:sectPr or ancestor::w:tbl)">
  184.                     <xsl:attribute name="style:master-page-name">Standard<xsl:value-of select="$section-property-number + 1"/>
  185.                     </xsl:attribute>
  186.                 </xsl:when>
  187.                 <xsl:when test="$paragraph-number = 1">
  188.                     <xsl:attribute name="style:master-page-name">Standard1</xsl:attribute>
  189.                 </xsl:when>
  190.             </xsl:choose>
  191.             <style:paragraph-properties>
  192.                 <xsl:apply-templates select="w:pPr"/>
  193.             </style:paragraph-properties>
  194.             <style:text-properties>
  195.                 <xsl:apply-templates select="w:pPr/w:rPr"/>
  196.                 <xsl:apply-templates select="w:rPr"/>
  197.             </style:text-properties>
  198.         </style:style>
  199.         <xsl:if test="w:r/w:br/@w:type='page'">
  200.             <style:style style:family="paragraph" style:name="P{$paragraph-number}page-break">
  201.                 <xsl:if test="w:pPr/w:pStyle">
  202.                     <xsl:attribute name="style:parent-style-name">
  203.                         <xsl:value-of select="concat('w',translate(w:pPr/w:pStyle/@w:val,' ~`!@#$%^*(&)+/,;?<>{}[]:','_'))"/>
  204.                     </xsl:attribute>
  205.                 </xsl:if>
  206.                 <xsl:choose>
  207.                     <xsl:when test="generate-id($last-section-property[last()]/following::w:p[1]) = generate-id(.) and not(ancestor::w:sectPr or ancestor::w:tbl)">
  208.                         <xsl:attribute name="style:master-page-name">Standard<xsl:value-of select="$section-property-number + 1"/>
  209.                         </xsl:attribute>
  210.                     </xsl:when>
  211.                     <xsl:when test="$paragraph-number = 1">
  212.                         <xsl:attribute name="style:master-page-name">Standard1</xsl:attribute>
  213.                     </xsl:when>
  214.                 </xsl:choose>
  215.                 <style:paragraph-properties fo:break-before="page">
  216.                     <xsl:apply-templates select="w:pPr"/>
  217.                 </style:paragraph-properties>
  218.             </style:style>
  219.         </xsl:if>
  220.         <xsl:if test="w:r/w:br/@w:type='column'">
  221.             <style:style style:family="paragraph" style:name="P{$paragraph-number}column-break">
  222.                 <xsl:if test="w:pPr/w:pStyle">
  223.                     <xsl:attribute name="style:parent-style-name">
  224.                         <xsl:value-of select="concat('w',translate(w:pPr/w:pStyle/@w:val,' ~`!@#$%^*(&)+/,;?<>{}[]:','_'))"/>
  225.                     </xsl:attribute>
  226.                 </xsl:if>
  227.                 <xsl:choose>
  228.                     <xsl:when test="generate-id($last-section-property[last()]/following::w:p[1]) = generate-id(.) and not(ancestor::w:sectPr or ancestor::w:tbl)">
  229.                         <xsl:attribute name="style:master-page-name">Standard<xsl:value-of select="$section-property-number + 1"/>
  230.                         </xsl:attribute>
  231.                     </xsl:when>
  232.                     <xsl:when test="$paragraph-number = 1">
  233.                         <xsl:attribute name="style:master-page-name">Standard1</xsl:attribute>
  234.                     </xsl:when>
  235.                 </xsl:choose>
  236.                 <style:paragraph-properties fo:break-before="column">
  237.                     <xsl:apply-templates select="w:pPr"/>
  238.                 </style:paragraph-properties>
  239.             </style:style>
  240.         </xsl:if>
  241.     </xsl:template>
  242.     <xsl:template match="w:pPr">
  243.         <xsl:if test="w:ind/@w:left">
  244.             <xsl:attribute name="fo:margin-left">
  245.                 <xsl:call-template name="ConvertMeasure">
  246.                     <xsl:with-param name="value" select="concat(w:ind/@w:left, 'twip')"/>
  247.                 </xsl:call-template>cm</xsl:attribute>
  248.         </xsl:if>
  249.         <xsl:if test="w:ind/@w:right">
  250.             <xsl:attribute name="fo:margin-right">
  251.                 <xsl:call-template name="ConvertMeasure">
  252.                     <xsl:with-param name="value" select="concat(w:ind/@w:right, 'twip')"/>
  253.                 </xsl:call-template>cm</xsl:attribute>
  254.         </xsl:if>
  255.         <xsl:if test="w:ind/@w:first-line">
  256.             <xsl:attribute name="fo:text-indent">
  257.                 <xsl:call-template name="ConvertMeasure">
  258.                     <xsl:with-param name="value" select="concat(w:ind/@w:first-line, 'twip')"/>
  259.                 </xsl:call-template>cm</xsl:attribute>
  260.         </xsl:if>
  261.         <xsl:if test="w:ind/@w:hanging">
  262.             <xsl:attribute name="fo:text-indent">
  263.                 <xsl:call-template name="ConvertMeasure">
  264.                     <xsl:with-param name="value" select="concat('-',w:ind/@w:hanging, 'twip')"/>
  265.                 </xsl:call-template>cm</xsl:attribute>
  266.         </xsl:if>
  267.         <!-- bi-directional support-->
  268.         <xsl:if test="w:bidi">
  269.             <xsl:choose>
  270.                 <xsl:when test="w:bidi/@w:val = 'off'">
  271.                     <xsl:attribute name="fo:text-align">start</xsl:attribute>
  272.                 </xsl:when>
  273.                 <xsl:otherwise>
  274.                     <xsl:attribute name="style:writing-mode">rl-tb</xsl:attribute>
  275.                     <xsl:attribute name="fo:text-align">end</xsl:attribute>
  276.                 </xsl:otherwise>
  277.             </xsl:choose>
  278.         </xsl:if>
  279.         <xsl:if test="w:jc">
  280.             <xsl:choose>
  281.                 <xsl:when test="w:jc/@w:val = 'center'">
  282.                     <xsl:attribute name="fo:text-align">center</xsl:attribute>
  283.                 </xsl:when>
  284.                 <xsl:when test="w:jc/@w:val = 'left'">
  285.                     <xsl:choose>
  286.                         <xsl:when test="w:bidi and not(w:bidi/@w:val = 'off')">
  287.                             <xsl:attribute name="fo:text-align">end</xsl:attribute>
  288.                         </xsl:when>
  289.                         <xsl:otherwise>
  290.                             <xsl:attribute name="fo:text-align">start</xsl:attribute>
  291.                         </xsl:otherwise>
  292.                     </xsl:choose>
  293.                 </xsl:when>
  294.                 <xsl:when test="w:jc/@w:val = 'right'">
  295.                     <xsl:choose>
  296.                         <xsl:when test="w:bidi and not(w:bidi/@w:val = 'off')">
  297.                             <xsl:attribute name="fo:text-align">start</xsl:attribute>
  298.                         </xsl:when>
  299.                         <xsl:otherwise>
  300.                             <xsl:attribute name="fo:text-align">end</xsl:attribute>
  301.                         </xsl:otherwise>
  302.                     </xsl:choose>
  303.                 </xsl:when>
  304.                 <xsl:otherwise>
  305.                     <xsl:attribute name="fo:text-align">justify</xsl:attribute>
  306.                     <xsl:attribute name="style:justify-single-word">false</xsl:attribute>
  307.                 </xsl:otherwise>
  308.             </xsl:choose>
  309.         </xsl:if>
  310.         <xsl:if test="w:spacing">
  311.             <xsl:choose>
  312.                 <xsl:when test="w:spacing/@w:line-rule = 'at-least'">
  313.                     <xsl:attribute name="style:line-height-at-least">
  314.                         <xsl:call-template name="ConvertMeasure">
  315.                             <xsl:with-param name="value" select="concat(w:spacing/@w:line, 'twip')"/>
  316.                         </xsl:call-template>cm</xsl:attribute>
  317.                 </xsl:when>
  318.                 <xsl:when test="w:spacing/@w:line-rule = 'auto'">
  319.                     <xsl:attribute name="fo:line-height">
  320.                         <xsl:value-of select="round(w:spacing/@w:line div 240 * 100)"/>%</xsl:attribute>
  321.                 </xsl:when>
  322.                 <xsl:when test="w:spacing/@w:line-rule = 'exact'">
  323.                     <xsl:attribute name="fo:line-height">
  324.                         <xsl:call-template name="ConvertMeasure">
  325.                             <xsl:with-param name="value" select="concat(w:spacing/@w:line, 'twip')"/>
  326.                         </xsl:call-template>cm</xsl:attribute>
  327.                 </xsl:when>
  328.             </xsl:choose>
  329.             <xsl:if test="w:spacing/@w:before">
  330.                 <xsl:attribute name="fo:margin-top">
  331.                     <xsl:call-template name="ConvertMeasure">
  332.                         <xsl:with-param name="value" select="concat(w:spacing/@w:before, 'twip')"/>
  333.                     </xsl:call-template>cm</xsl:attribute>
  334.             </xsl:if>
  335.             <xsl:if test="w:spacing/@w:after">
  336.                 <xsl:attribute name="fo:margin-bottom">
  337.                     <xsl:call-template name="ConvertMeasure">
  338.                         <xsl:with-param name="value" select="concat(w:spacing/@w:after, 'twip')"/>
  339.                     </xsl:call-template>cm</xsl:attribute>
  340.             </xsl:if>
  341.         </xsl:if>
  342.         <xsl:if test="w:shd">
  343.             <xsl:variable name="background-color">
  344.                 <xsl:choose>
  345.                     <xsl:when test="string-length(w:shd/@w:fill) = 6">
  346.                         <xsl:value-of select="concat('#', w:shd/@w:fill)"/>
  347.                     </xsl:when>
  348.                     <xsl:otherwise>#000000</xsl:otherwise>
  349.                 </xsl:choose>
  350.             </xsl:variable>
  351.             <xsl:choose>
  352.                 <xsl:when test="w:shd/@w:val = 'solid'">
  353.                     <xsl:attribute name="fo:background-color">
  354.                         <xsl:value-of select="$background-color"/>
  355.                     </xsl:attribute>
  356.                 </xsl:when>
  357.                 <!-- patterns are necessary in the future. glu -->
  358.                 <xsl:otherwise/>
  359.             </xsl:choose>
  360.         </xsl:if>
  361.         <xsl:if test="w:pageBreakBefore and not(w:pageBreakBefore/@w:val = 'off')">
  362.             <xsl:attribute name="fo:break-before">page</xsl:attribute>
  363.         </xsl:if>
  364.         <xsl:if test="w:pageBreakBefore and w:pageBreakBefore/@w:val = 'off'">
  365.             <xsl:attribute name="fo:break-before">auto</xsl:attribute>
  366.         </xsl:if>
  367.         <xsl:if test="w:keepNext">
  368.             <xsl:attribute name="fo:keep-with-next">always</xsl:attribute>
  369.         </xsl:if>
  370.         <!--
  371.         <xsl:if test="w:keepLines">
  372.             <xsl:attribute name="style:break-inside">avoid</xsl:attribute>
  373.         </xsl:if>
  374.         -->
  375.         <xsl:if test="w:widowControl='on'">
  376.             <xsl:attribute name="fo:widows">2</xsl:attribute>
  377.             <xsl:attribute name="fo:orphans">2</xsl:attribute>
  378.         </xsl:if>
  379.         <!--
  380.         <xsl:if test="w:suppressAutoHyphens">
  381.             <xsl:attribute name="fo:hyphenate">false</xsl:attribute>
  382.         </xsl:if>
  383.         -->
  384.         <xsl:if test="w:kinsoku/@w:val='off'">
  385.             <xsl:attribute name="style:line-break">normal</xsl:attribute>
  386.         </xsl:if>
  387.         <xsl:if test="w:overflowPunct/@w:val='off'">
  388.             <xsl:attribute name="style:punctuation-wrap">simple</xsl:attribute>
  389.         </xsl:if>
  390.         <xsl:if test="w:autoSpaceDE/@w:val='off' or w:autoSpaceDN/@w:val='off'">
  391.             <xsl:attribute name="style:text-autospace">none</xsl:attribute>
  392.         </xsl:if>
  393.         <xsl:if test="w:textAlignment">
  394.             <xsl:choose>
  395.                 <xsl:when test="w:textAlignment/@w:val='center'">
  396.                     <xsl:attribute name="style:vertical-align">middle</xsl:attribute>
  397.                 </xsl:when>
  398.                 <xsl:when test="w:textAlignment/@w:val='baseline'">
  399.                     <xsl:attribute name="style:vertical-align">bottom</xsl:attribute>
  400.                 </xsl:when>
  401.                 <xsl:otherwise>
  402.                     <xsl:attribute name="style:vertical-align">
  403.                         <xsl:value-of select="w:textAlignment/@w:val"/>
  404.                     </xsl:attribute>
  405.                 </xsl:otherwise>
  406.             </xsl:choose>
  407.         </xsl:if>
  408.         <xsl:if test="w:pBdr">
  409.             <xsl:if test="w:pBdr/w:top">
  410.                 <xsl:call-template name="get-table-border">
  411.                     <xsl:with-param name="style-pos" select="'top'"/>
  412.                     <xsl:with-param name="style-position-0" select="w:pBdr/w:top"/>
  413.                 </xsl:call-template>
  414.                 <xsl:attribute name="fo:padding-top">
  415.                     <xsl:call-template name="ConvertMeasure">
  416.                         <xsl:with-param name="value" select="concat(w:pBdr/w:top/@w:space,'pt')"/>
  417.                     </xsl:call-template>cm</xsl:attribute>
  418.             </xsl:if>
  419.             <xsl:if test="w:pBdr/w:left">
  420.                 <xsl:call-template name="get-table-border">
  421.                     <xsl:with-param name="style-pos" select="'left'"/>
  422.                     <xsl:with-param name="style-position-0" select="w:pBdr/w:left"/>
  423.                 </xsl:call-template>
  424.                 <xsl:attribute name="fo:padding-left">
  425.                     <xsl:call-template name="ConvertMeasure">
  426.                         <xsl:with-param name="value" select="concat(w:pBdr/w:left/@w:space,'pt')"/>
  427.                     </xsl:call-template>cm</xsl:attribute>
  428.             </xsl:if>
  429.             <xsl:if test="w:pBdr/w:right">
  430.                 <xsl:call-template name="get-table-border">
  431.                     <xsl:with-param name="style-pos" select="'right'"/>
  432.                     <xsl:with-param name="style-position-0" select="w:pBdr/w:right"/>
  433.                 </xsl:call-template>
  434.                 <xsl:attribute name="fo:padding-right">
  435.                     <xsl:call-template name="ConvertMeasure">
  436.                         <xsl:with-param name="value" select="concat(w:pBdr/w:right/@w:space,'pt')"/>
  437.                     </xsl:call-template>cm</xsl:attribute>
  438.             </xsl:if>
  439.             <xsl:if test="w:pBdr/w:bottom">
  440.                 <xsl:call-template name="get-table-border">
  441.                     <xsl:with-param name="style-pos" select="'bottom'"/>
  442.                     <xsl:with-param name="style-position-0" select="w:pBdr/w:bottom"/>
  443.                 </xsl:call-template>
  444.                 <xsl:attribute name="fo:padding-bottom">
  445.                     <xsl:call-template name="ConvertMeasure">
  446.                         <xsl:with-param name="value" select="concat(w:pBdr/w:bottom/@w:space,'pt')"/>
  447.                     </xsl:call-template>cm</xsl:attribute>
  448.             </xsl:if>
  449.             <xsl:if test="w:pBdr/*/@w:shadow='on'">
  450.                 <xsl:attribute name="style:shadow">#000000 0.15cm 0.15cm</xsl:attribute>
  451.             </xsl:if>
  452.         </xsl:if>
  453.         <xsl:if test="w:snapToGrid/@w:val='off'">
  454.             <xsl:attribute name="style:snap-to-layout-grid">false</xsl:attribute>
  455.         </xsl:if>
  456.         <xsl:if test="w:tabs">
  457.             <xsl:element name="style:tab-stops">
  458.                 <xsl:for-each select="w:tabs/w:tab">
  459.                     <xsl:element name="style:tab-stop">
  460.                         <xsl:attribute name="style:position">
  461.                             <xsl:if test="@w:pos < 0">
  462.                                 <xsl:message>
  463.                                     We meet a negative w:pos:<xsl:value-of select="@w:pos"/>.
  464.                                 </xsl:message>
  465.                                 <xsl:value-of select="'0cm'"/>
  466.                             </xsl:if>
  467.                             <xsl:if test="not(@w:pos < 0)">
  468.                                 <xsl:call-template name="ConvertMeasure">
  469.                                     <xsl:with-param name="value" select="concat(@w:pos, 'twip')"/>
  470.                                 </xsl:call-template>cm</xsl:if>
  471.                         </xsl:attribute>
  472.                         <xsl:choose>
  473.                             <xsl:when test="@w:val = 'decimal'">
  474.                                 <xsl:attribute name="style:type">char</xsl:attribute>
  475.                                 <xsl:attribute name="style:char">
  476.                                     <xsl:value-of select="' '"/>
  477.                                 </xsl:attribute>
  478.                             </xsl:when>
  479.                             <xsl:when test="@w:val = 'left' or @w:val = 'right' or @w:val = 'center' ">
  480.                                 <xsl:attribute name="style:type">
  481.                                     <xsl:value-of select="@w:val"/>
  482.                                 </xsl:attribute>
  483.                             </xsl:when>
  484.                             <xsl:otherwise>
  485.                                 <xsl:attribute name="style:type">char</xsl:attribute>
  486.                                 <xsl:attribute name="style:char">
  487.                                     <xsl:value-of select="' '"/>
  488.                                 </xsl:attribute>
  489.                             </xsl:otherwise>
  490.                         </xsl:choose>
  491.                         <!-- Detect leader chars in tabs (rp) -->
  492.                         <xsl:choose>
  493.                             <xsl:when test="@w:leader = 'hyphen'">
  494.                                 <xsl:attribute name="style:leader-style">solid</xsl:attribute>
  495.                                 <xsl:attribute name="style:leader-text">-</xsl:attribute>
  496.                             </xsl:when>
  497.                             <xsl:when test="@w:leader = 'underscore'">
  498.                                 <xsl:attribute name="style:leader-style">solid</xsl:attribute>
  499.                                 <xsl:attribute name="style:leader-text">_</xsl:attribute>
  500.                             </xsl:when>
  501.                             <xsl:when test="@w:leader = 'dot'">
  502.                                 <xsl:attribute name="style:leader-style">dotted</xsl:attribute>
  503.                                 <xsl:attribute name="style:leader-text">.</xsl:attribute>
  504.                             </xsl:when>
  505.                         </xsl:choose>
  506.                         <!-- end leader chars (rp) -->
  507.                     </xsl:element>
  508.                 </xsl:for-each>
  509.             </xsl:element>
  510.         </xsl:if>
  511.         <xsl:apply-templates select="w:rPr" mode="paragraph-properties"/>
  512.     </xsl:template>
  513.     <xsl:template match="w:rPr" mode="style">
  514.         <xsl:element name="style:style">
  515.             <xsl:attribute name="style:name">T<xsl:number from="/w:wordDocument/w:body" level="any" count="w:rPr" format="1"/>
  516.             </xsl:attribute>
  517.             <xsl:attribute name="style:family">text</xsl:attribute>
  518.             <xsl:if test="w:rStyle">
  519.                 <xsl:attribute name="style:parent-style-name">
  520.                     <xsl:value-of select="concat('w',translate(w:rStyle/@w:val,' ~`!@#$%^*(&)+/,;?<>{}[]:','_'))"/>
  521.                 </xsl:attribute>
  522.             </xsl:if>
  523.             <xsl:element name="style:text-properties">
  524.  
  525.                 <xsl:apply-templates select="current()"/> 
  526. <!--        <xsl:call-template name="text-properties"/> -->
  527.             </xsl:element>
  528.         </xsl:element>
  529.     </xsl:template>
  530.     <xsl:template match="w:rPr">
  531.         <xsl:if test="w:rFonts">
  532.             <xsl:if test="w:rFonts/@w:ascii">
  533.                 <xsl:attribute name="style:font-name">
  534.                     <xsl:value-of select="w:rFonts/@w:ascii"/>
  535.                 </xsl:attribute>
  536.                 <xsl:if test="ancestor::w:body">
  537.                     <xsl:attribute name="style:font-name-asian">
  538.                         <xsl:value-of select="w:rFonts/@w:ascii"/>
  539.                     </xsl:attribute>
  540.                     <xsl:attribute name="style:font-name-complex">
  541.                         <xsl:value-of select="w:rFonts/@w:ascii"/>
  542.                     </xsl:attribute>
  543.                 </xsl:if>
  544.             </xsl:if>
  545.             <xsl:if test="ancestor::w:styles">
  546.                 <xsl:if test="w:rFonts/@w:fareast">
  547.                     <xsl:attribute name="style:font-name-asian">
  548.                         <xsl:value-of select="w:rFonts/@w:fareast"/>
  549.                     </xsl:attribute>
  550.                 </xsl:if>
  551.                 <xsl:if test="w:rFonts/@w:cs">
  552.                     <xsl:attribute name="style:font-name-complex">
  553.                         <xsl:value-of select="w:rFonts/@w:cs"/>
  554.                     </xsl:attribute>
  555.                 </xsl:if>
  556.             </xsl:if>
  557.         </xsl:if>
  558.         <xsl:if test="parent::w:r">
  559.             <xsl:if test="w:b">
  560.                 <xsl:attribute name="fo:font-weight">bold</xsl:attribute>
  561.                 <xsl:attribute name="style:font-weight-asian">bold</xsl:attribute>
  562.             </xsl:if>
  563.             <xsl:if test="w:b-cs">
  564.                 <xsl:attribute name="style:font-weight-complex">bold</xsl:attribute>
  565.             </xsl:if>
  566.             <xsl:if test="w:i">
  567.                 <xsl:attribute name="fo:font-style">italic</xsl:attribute>
  568.                 <xsl:attribute name="style:font-style-asian">italic</xsl:attribute>
  569.             </xsl:if>
  570.             <xsl:if test="w:i-cs">
  571.                 <xsl:attribute name="style:font-style-complex">italic</xsl:attribute>
  572.             </xsl:if>
  573.         </xsl:if>
  574.         <xsl:if test="w:caps">
  575.             <xsl:attribute name="fo:text-transform">uppercase</xsl:attribute>
  576.         </xsl:if>
  577.         <xsl:if test="w:smallCaps">
  578.             <xsl:attribute name="fo:font-variant">small-caps</xsl:attribute>
  579.         </xsl:if>
  580.         <xsl:if test="w:strike">
  581.             <xsl:attribute name="style:text-line-through-style">solid</xsl:attribute>
  582.         </xsl:if>
  583.         <xsl:if test="w:dstrike">
  584.             <xsl:attribute name="style:text-line-through-style">solid</xsl:attribute>
  585.             <xsl:attribute name="style:text-line-through-type">double</xsl:attribute>
  586.         </xsl:if>
  587.         <xsl:if test="w:outline">
  588.             <xsl:attribute name="style:text-outline">true</xsl:attribute>
  589.         </xsl:if>
  590.         <xsl:if test="w:shadow">
  591.             <xsl:attribute name="fo:text-shadow">1pt 1pt</xsl:attribute>
  592.         </xsl:if>
  593.         <xsl:if test="w:imprint">
  594.             <xsl:attribute name="style:font-relief">engraved</xsl:attribute>
  595.         </xsl:if>
  596.         <xsl:if test="w:emboss">
  597.             <xsl:attribute name="style:font-relief">embossed</xsl:attribute>
  598.         </xsl:if>
  599.         <xsl:if test="w:vanish">
  600.             <xsl:attribute name="text:display">true</xsl:attribute>
  601.         </xsl:if>
  602.         <xsl:if test="w:color[not(@w:val = 'auto')]">
  603.             <xsl:attribute name="fo:color">#<xsl:value-of select="w:color/@w:val"/>
  604.             </xsl:attribute>
  605.         </xsl:if>
  606.         <xsl:if test="w:spacing">
  607.             <xsl:attribute name="fo:letter-spacing">
  608.                 <xsl:call-template name="ConvertMeasure">
  609.                     <xsl:with-param name="value" select="concat(w:spacing/@w:val,'twip')"/>
  610.                 </xsl:call-template>cm</xsl:attribute>
  611.         </xsl:if>
  612.         <xsl:if test="w:w/@w:val">
  613.             <xsl:attribute name="style:text-scale">
  614.                 <xsl:value-of select="concat(w:w/@w:val, '%')"/>
  615.             </xsl:attribute>
  616.         </xsl:if>
  617.         <xsl:if test="w:vertAlign or w:position">
  618.             <xsl:variable name="height">
  619.                 <xsl:choose>
  620.                     <xsl:when test="w:vertAlign[@w:val = 'superscript' or @w:val = 'subscript']">58%</xsl:when>
  621.                     <xsl:otherwise>100%</xsl:otherwise>
  622.                 </xsl:choose>
  623.             </xsl:variable>
  624.             <xsl:variable name="position">
  625.                 <xsl:choose>
  626.                     <xsl:when test="w:position">
  627.                         <!-- con't get font height easily, so just set w:val as percentage. glu -->
  628.                         <xsl:value-of select="concat( w:position/@w:val, '%')"/>
  629.                     </xsl:when>
  630.                     <xsl:when test="w:vertAlign[@w:val = 'superscript']">super</xsl:when>
  631.                     <xsl:when test="w:vertAlign[@w:val = 'subscript']">sub</xsl:when>
  632.                 </xsl:choose>
  633.             </xsl:variable>
  634.             <xsl:attribute name="style:text-position">
  635.                 <xsl:value-of select="concat($position, ' ', $height)"/>
  636.             </xsl:attribute>
  637.         </xsl:if>
  638.         <xsl:if test="w:sz">
  639.             <xsl:attribute name="fo:font-size">
  640.                 <xsl:value-of select="translate(w:sz/@w:val,'Na','0') div 2"/>pt</xsl:attribute>
  641.             <xsl:attribute name="style:font-size-asian">
  642.                 <xsl:value-of select="translate(w:sz/@w:val,'Na','0') div 2"/>pt</xsl:attribute>
  643.         </xsl:if>
  644.         <xsl:if test="w:sz-cs">
  645.             <xsl:attribute name="style:font-size-complex">
  646.                 <xsl:value-of select="w:sz-cs/@w:val div 2"/>pt</xsl:attribute>
  647.         </xsl:if>
  648.         <xsl:if test="w:highlight">
  649.             <xsl:choose>
  650.                 <xsl:when test="w:highlight/@w:val='black'">
  651.                     <xsl:attribute name="fo:background-color">#000000</xsl:attribute>
  652.                 </xsl:when>
  653.                 <xsl:when test="w:highlight/@w:val='yellow'">
  654.                     <xsl:attribute name="fo:background-color">#ffff00</xsl:attribute>
  655.                 </xsl:when>
  656.                 <xsl:when test="w:highlight/@w:val='green'">
  657.                     <xsl:attribute name="fo:background-color">#00ff00</xsl:attribute>
  658.                 </xsl:when>
  659.                 <xsl:when test="w:highlight/@w:val='cyan'">
  660.                     <xsl:attribute name="fo:background-color">#00ffff</xsl:attribute>
  661.                 </xsl:when>
  662.                 <xsl:when test="w:highlight/@w:val='magenta'">
  663.                     <xsl:attribute name="fo:background-color">#ff00ff</xsl:attribute>
  664.                 </xsl:when>
  665.                 <xsl:when test="w:highlight/@w:val='blue'">
  666.                     <xsl:attribute name="fo:background-color">#0000ff</xsl:attribute>
  667.                 </xsl:when>
  668.                 <xsl:when test="w:highlight/@w:val='red'">
  669.                     <xsl:attribute name="fo:background-color">#ff0000</xsl:attribute>
  670.                 </xsl:when>
  671.                 <xsl:when test="w:highlight/@w:val='dark-blue'">
  672.                     <xsl:attribute name="fo:background-color">#000080</xsl:attribute>
  673.                 </xsl:when>
  674.                 <xsl:when test="w:highlight/@w:val='dark-cyan'">
  675.                     <xsl:attribute name="fo:background-color">#008080</xsl:attribute>
  676.                 </xsl:when>
  677.                 <xsl:when test="w:highlight/@w:val='dark-green'">
  678.                     <xsl:attribute name="fo:background-color">#008000</xsl:attribute>
  679.                 </xsl:when>
  680.                 <xsl:when test="w:highlight/@w:val='dark-magenta'">
  681.                     <xsl:attribute name="fo:background-color">#800080</xsl:attribute>
  682.                 </xsl:when>
  683.                 <xsl:when test="w:highlight/@w:val='dark-red'">
  684.                     <xsl:attribute name="fo:background-color">#800000</xsl:attribute>
  685.                 </xsl:when>
  686.                 <xsl:when test="w:highlight/@w:val='dark-yellow'">
  687.                     <xsl:attribute name="fo:background-color">#808000</xsl:attribute>
  688.                 </xsl:when>
  689.                 <xsl:when test="w:highlight/@w:val='dark-gray'">
  690.                     <xsl:attribute name="fo:background-color">#808080</xsl:attribute>
  691.                 </xsl:when>
  692.                 <xsl:when test="w:highlight/@w:val='light-gray'">
  693.                     <xsl:attribute name="fo:background-color">#c0c0c0</xsl:attribute>
  694.                 </xsl:when>
  695.             </xsl:choose>
  696.         </xsl:if>
  697.         <xsl:if test="w:u">
  698.             <xsl:if test="w:u/@w:val = 'thick' or contains(w:u/@w:val,'-heavy')">
  699.                 <xsl:attribute name="style:text-underline-width">bold</xsl:attribute>
  700.             </xsl:if>
  701.             <xsl:if test="w:u/@w:val = 'double' or contains(w:u/@w:val,'-double')">
  702.                 <xsl:attribute name="style:text-underline-type">double</xsl:attribute>
  703.             </xsl:if>
  704.             <xsl:choose>
  705.                 <xsl:when test="w:u/@w:val = 'words' or w:u/@w:val = 'single' or w:u/@w:val = 'thick' or w:u/@w:val = 'double'">
  706.                     <xsl:attribute name="style:text-underline-style">solid</xsl:attribute>
  707.                 </xsl:when>
  708.                 <xsl:when test="contains(w:u/@w:val , 'dotted')">
  709.                     <xsl:attribute name="style:text-underline-style">dotted</xsl:attribute>
  710.                 </xsl:when>
  711.                 <xsl:when test="w:u/@w:val = 'dashed-heavy' or w:u/@w:val = 'dash'">
  712.                     <xsl:attribute name="style:text-underline-style">dash</xsl:attribute>
  713.                 </xsl:when>
  714.                 <xsl:when test="w:u/@w:val = 'dash-long' or w:u/@w:val = 'dash-long-heavy'">
  715.                     <xsl:attribute name="style:text-underline-style">long-dash</xsl:attribute>
  716.                 </xsl:when>
  717.                 <xsl:when test="w:u/@w:val = 'dash-dot-heavy' or w:u/@w:val = 'dot-dash'">
  718.                     <xsl:attribute name="style:text-underline-style">dot-dash</xsl:attribute>
  719.                 </xsl:when>
  720.                 <xsl:when test="w:u/@w:val = 'dash-dot-dot-heavy' or w:u/@w:val = 'dot-dot-dash'">
  721.                     <xsl:attribute name="style:text-underline-style">dot-dot-dash</xsl:attribute>
  722.                 </xsl:when>
  723.                 <xsl:when test="w:u/@w:val = 'wavy-heavy' or w:u/@w:val = 'wavy-double' or w:u/@w:val = 'wavy'">
  724.                     <xsl:attribute name="style:text-underline-style">wave</xsl:attribute>
  725.                 </xsl:when>
  726.                 <xsl:otherwise>
  727.                     <xsl:if test="string-length(style:text-underline-style) > 0">
  728.                         <xsl:attribute name="style:text-underline-style">
  729.                             <xsl:value-of select="w:u/@w:val"/>
  730.                         </xsl:attribute>
  731.                     </xsl:if>
  732.                 </xsl:otherwise>
  733.             </xsl:choose>
  734.             <xsl:if test="w:u/@w:color and not(w:u/@w:color = 'auto')">
  735.                 <xsl:attribute name="style:text-underline-color">#<xsl:value-of select="w:u/@w:color"/>
  736.                 </xsl:attribute>
  737.             </xsl:if>
  738.         </xsl:if>
  739.         <xsl:if test="w:effect[@w:val = 'blink-background']">
  740.             <xsl:attribute name="style:text-blinking">true</xsl:attribute>
  741.         </xsl:if>
  742.         <xsl:if test="w:shd and not(w:highlight)">
  743.             <xsl:if test="string-length(w:shd/@w:fill) = 6">
  744.                 <xsl:attribute name="fo:background-color">#<xsl:value-of select="w:shd/@w:fill"/>
  745.                 </xsl:attribute>
  746.             </xsl:if>
  747.         </xsl:if>
  748.         <xsl:if test="w:em">
  749.             <xsl:choose>
  750.                 <xsl:when test="w:em/@w:val = 'comma'">
  751.                     <xsl:attribute name="style:text-emphasize">accent below</xsl:attribute>
  752.                 </xsl:when>
  753.                 <xsl:when test="w:em/@w:val = 'under-dot'">
  754.                     <xsl:attribute name="style:text-emphasize">disc below</xsl:attribute>
  755.                 </xsl:when>
  756.                 <xsl:when test="w:em/@w:val = 'dot' or w:em/@w:val = 'circle' ">
  757.                     <xsl:attribute name="style:text-emphasize">
  758.                         <xsl:value-of select=" concat(w:em/@w:val,' below') "/>
  759.                     </xsl:attribute>
  760.                 </xsl:when>
  761.                 <xsl:otherwise>
  762.                     <xsl:attribute name="style:text-emphasize">none</xsl:attribute>
  763.                 </xsl:otherwise>
  764.             </xsl:choose>
  765.         </xsl:if>
  766.         <xsl:if test="w:lang">
  767.             <xsl:if test="w:lang/@w:val">
  768.                 <xsl:attribute name="fo:language">
  769.                     <xsl:choose>
  770.                         <xsl:when test="contains(w:lang/@w:val, '-')">
  771.                             <xsl:value-of select="substring-before( w:lang/@w:val, '-')"/>
  772.                         </xsl:when>
  773.                         <xsl:otherwise>
  774.                             <xsl:value-of select="w:lang/@w:val"/>
  775.                         </xsl:otherwise>
  776.                     </xsl:choose>
  777.                     <!--xsl:value-of select="substring-before( w:lang/@w:val, '-')"/-->
  778.                 </xsl:attribute>
  779.                 <xsl:attribute name="fo:country">
  780.                     <xsl:choose>
  781.                         <xsl:when test="contains(w:lang/@w:val, '-')">
  782.                             <xsl:value-of select="substring-before( w:lang/@w:val, '-')"/>
  783.                         </xsl:when>
  784.                         <xsl:otherwise>
  785.                             <xsl:value-of select="w:lang/@w:val"/>
  786.                         </xsl:otherwise>
  787.                     </xsl:choose>
  788.                     <!--xsl:value-of select="substring-after( w:lang/@w:val, '-')"/-->
  789.                 </xsl:attribute>
  790.             </xsl:if>
  791.         </xsl:if>
  792.     </xsl:template>
  793.     <xsl:template match="w:rPr" mode="paragraph-properties">
  794.         <!--  right-to-left support-->
  795.         <xsl:if test="w:rtl and not(w:rtl/@w:val = 'off')">
  796.             <xsl:attribute name="style:writing-mode">rl-tb</xsl:attribute>
  797.             <xsl:attribute name="fo:text-align">end</xsl:attribute>
  798.         </xsl:if>
  799.     </xsl:template>
  800.     <xsl:template match="w:p">
  801.         <xsl:choose>
  802.             <!-- because word treats page breaks as separate tags, we must split some paragraphs up so that we can
  803.             give the sub para a fo:break-before ="page" or column attribute. -->
  804.             <xsl:when test="w:r[w:br/@w:type='page' or w:br/@w:type='column']">
  805.                 <xsl:call-template name="process-breaks-in-paragraph"/>
  806.             </xsl:when>
  807.             <xsl:otherwise>
  808.                 <xsl:call-template name="process-common-paragraph"/>
  809.             </xsl:otherwise>
  810.         </xsl:choose>
  811.     </xsl:template>
  812.     <xsl:template name="process-breaks-in-paragraph">
  813.         <xsl:variable name="textruns-with-break" select="w:r[w:br/@w:type='page' or w:br/@w:type='column']"/>
  814.         <xsl:call-template name="create-sub-paragraph">
  815.             <xsl:with-param name="textruns" select="$textruns-with-break[1]/preceding-sibling::w:r"/>
  816.         </xsl:call-template>
  817.         <xsl:for-each select="$textruns-with-break">
  818.             <xsl:variable name="break-position" select="position()"/>
  819.             <xsl:call-template name="create-sub-paragraph">
  820.                 <!-- added following-sibling::w:fldSimple | following-sibling::w:hlink | following-sibling::aml:annotation to enable these elements to be processed when there are breaks happen  G.Yang -->
  821.                 <xsl:with-param name="textruns" select="following-sibling::w:r[not(w:br/@w:type='page' or w:br/@w:type='column') and (count(preceding::w:r[w:br/@w:type='page' or w:br/@w:type='column']) = $break-position)] | following-sibling::w:fldSimple[count(preceding::w:r[w:br/@w:type='page' or w:br/@w:type='column']) = $break-position] | following-sibling::w:hlink[count(preceding::w:r[w:br/@w:type='page' or w:br/@w:type='column']) = $break-position] | following-sibling::aml:annotation[count(preceding::w:r[w:br/@w:type='page' or w:br/@w:type='column']) = $break-position] "/>
  822.                 <xsl:with-param name="textruns-with-break" select="current()"/>
  823.             </xsl:call-template>
  824.         </xsl:for-each>
  825.     </xsl:template>
  826.     <xsl:template name="create-sub-paragraph">
  827.         <xsl:param name="textruns"/>
  828.         <xsl:param name="textruns-with-break"/>
  829.         <xsl:if test="$textruns or $textruns-with-break">
  830.             <xsl:variable name="curr-num">
  831.                 <xsl:number from="/w:wordDocument/w:body" level="any" count="w:p" format="1"/>
  832.             </xsl:variable>
  833.             <text:p>
  834.                 <xsl:choose>
  835.                     <xsl:when test="$textruns-with-break">
  836.                         <xsl:attribute name="text:style-name">
  837.                             <xsl:value-of select="concat('P',$curr-num,w:br/@w:type, '-break')"/>
  838.                         </xsl:attribute>
  839.                         <xsl:apply-templates select="$textruns-with-break"/>
  840.                     </xsl:when>
  841.                     <xsl:otherwise>
  842.                         <xsl:attribute name="text:style-name">
  843.                             <xsl:value-of select="concat( 'P', $curr-num)"/>
  844.                         </xsl:attribute>
  845.                     </xsl:otherwise>
  846.                 </xsl:choose>
  847.                 <xsl:if test="$textruns">
  848.                     <xsl:apply-templates select="$textruns"/>
  849.                 </xsl:if>
  850.             </text:p>
  851.         </xsl:if>
  852.     </xsl:template>
  853.     <xsl:template name="process-common-paragraph">
  854.         <xsl:variable name="heading-or-paragraph">
  855.             <xsl:choose>
  856.                 <xsl:when test="key('heading-style', w:pPr/w:pStyle/@w:val)">text:h</xsl:when>
  857.                 <xsl:otherwise>text:p</xsl:otherwise>
  858.             </xsl:choose>
  859.         </xsl:variable>
  860.         <xsl:element name="{$heading-or-paragraph}">
  861.             <xsl:if test="$heading-or-paragraph = 'text:h'">
  862.                 <xsl:attribute name="text:outline-level">
  863.                     <xsl:value-of select="key('heading-style',w:pPr/w:pStyle/@w:val)/w:pPr/w:outlineLvl/@w:val + 1"/>
  864.                 </xsl:attribute>
  865.             </xsl:if>
  866.             <xsl:variable name="curr-num">
  867.                 <xsl:number from="/w:wordDocument/w:body" level="any" count="w:p" format="1"/>
  868.             </xsl:variable>
  869.             <xsl:attribute name="text:style-name">
  870.                 <xsl:value-of select="concat( 'P', $curr-num)"/>
  871.             </xsl:attribute>
  872.             <xsl:variable name="bookmark-and-paragraph" select="preceding::aml:annotation[(@w:type = 'Word.Bookmark.Start' or @w:type = 'Word.Bookmark.End') and not(ancestor::w:p)] | preceding::w:p"/>
  873.             <xsl:if test="count($bookmark-and-paragraph) > 0 and name($bookmark-and-paragraph[last()]) = 'aml:annotation'">
  874.                 <xsl:call-template name="create-bookmark">
  875.                     <xsl:with-param name="bookmark-and-paragraph" select="$bookmark-and-paragraph"/>
  876.                     <xsl:with-param name="position" select="count($bookmark-and-paragraph)"/>
  877.                 </xsl:call-template>
  878.             </xsl:if>
  879.             <xsl:apply-templates select="w:r | w:fldSimple | w:hlink | aml:annotation"/>
  880.             <xsl:if test="not(following::w:p)">
  881.                 <xsl:apply-templates select="following::aml:annotation[(@w:type = 'Word.Bookmark.Start' or @w:type = 'Word.Bookmark.End') and not(ancestor::w:p)]"/>
  882.             </xsl:if>
  883.         </xsl:element>
  884.     </xsl:template>
  885.     <xsl:template name="create-bookmark">
  886.         <xsl:param name="bookmark-and-paragraph"/>
  887.         <xsl:param name="position"/>
  888.         <xsl:choose>
  889.             <xsl:when test="name($bookmark-and-paragraph[$position]) = 'aml:annotation'">
  890.                 <xsl:if test="$position > 0">
  891.                     <xsl:call-template name="create-bookmark">
  892.                         <xsl:with-param name="bookmark-and-paragraph" select="$bookmark-and-paragraph"/>
  893.                         <xsl:with-param name="position" select="$position - 1"/>
  894.                     </xsl:call-template>
  895.                 </xsl:if>
  896.             </xsl:when>
  897.             <xsl:otherwise>
  898.                 <xsl:call-template name="output-bookmark">
  899.                     <xsl:with-param name="bookmark-and-paragraph" select="$bookmark-and-paragraph"/>
  900.                     <xsl:with-param name="position" select="$position + 1"/>
  901.                 </xsl:call-template>
  902.             </xsl:otherwise>
  903.         </xsl:choose>
  904.     </xsl:template>
  905.     <xsl:template name="output-bookmark">
  906.         <xsl:param name="bookmark-and-paragraph"/>
  907.         <xsl:param name="position"/>
  908.         <xsl:apply-templates select="$bookmark-and-paragraph[$position]"/>
  909.         <xsl:if test="$position < count($bookmark-and-paragraph)">
  910.             <xsl:call-template name="output-bookmark">
  911.                 <xsl:with-param name="bookmark-and-paragraph" select="$bookmark-and-paragraph"/>
  912.                 <xsl:with-param name="position" select="$position + 1"/>
  913.             </xsl:call-template>
  914.         </xsl:if>
  915.     </xsl:template>
  916.     <!-- WordML contains multiple w:t within one w:r, so in Star Writer text:span should correspond to w:t glu -->
  917.     <xsl:template match="w:r">
  918.         <xsl:choose>
  919.             <xsl:when test="(preceding-sibling::w:r) or (w:rPr)">
  920.                 <!-- add this condition to prevent from  printing the value of DATE, TIME, PRINTDATE, CREATEDATE, SAVEDATE, PAGE, NUMPAGES etc. fields  in-between w:fldchar begin and w:fldchar end   G.Yang.-->
  921.                 <xsl:if test="not (preceding-sibling::w:r/w:instrText[substring(normalize-space(.),1,4) = 'DATE'  or substring(normalize-space(.),1,4) = 'TIME'  or  substring(normalize-space(.),1,9) = 'PRINTDATE'  or substring(normalize-space(.),1,10) = 'CREATEDATE'  or substring(normalize-space(.),1,8) = 'SAVEDATE' or substring(normalize-space(.),1,4) = 'PAGE' or substring(normalize-space(.),1,8) = 'NUMPAGES'  or substring(normalize-space(.),1,8) = 'NUMWORDS' or substring(normalize-space(.),1,8) = 'NUMCHARS' or substring(normalize-space(.),1,6) = 'REVNUM' or substring(normalize-space(.),1,7) = 'AUTONUM'  or  substring(normalize-space(.),1,10) = 'AUTONUMLGL' or substring(normalize-space(.),1,10) = 'AUTONUMOUT' or substring(normalize-space(.),1,3) = 'SEQ' or substring(normalize-space(.),1,6) = 'AUTHOR' or substring(normalize-space(.),1,5) = 'TITLE'  or substring(normalize-space(.),1,7) = 'SUBJECT'  or substring(normalize-space(.),1,8) = 'KEYWORDS' or substring(normalize-space(.),1,6) = 'FILLIN'  or substring(normalize-space(.),1,11) = 'DOCPROPERTY' or substring(normalize-space(.),1,10) = 'MERGEFIELD' or substring(normalize-space(.),1,8) = 'MERGEREC' or substring(normalize-space(.),1,4) = 'NEXT' or substring( normalize-space(.),1,9) = 'HYPERLINK' or substring( normalize-space(.),1,3) = 'REF' ][1]  and (following-sibling::w:r/w:fldChar[@w:fldCharType='end'] or (  not(preceding-sibling::w:r/w:fldChar[@w:fldCharType='end'] ) and parent::w:p/following-sibling::w:p/w:r/w:fldChar[@w:fldCharType='end'])) )">
  922.                     <text:span>
  923.                         <xsl:choose>
  924.                             <xsl:when test="w:rPr/w:rStyle">
  925.                                 <xsl:attribute name="text:style-name">
  926.                                     <xsl:value-of select="concat('w', translate(w:rPr/w:rStyle/@w:val,' ~`!@#$%^*(&)+/,;?<>{}[]:','_'))"/>
  927.                                 </xsl:attribute>
  928.                             </xsl:when>
  929.                             <xsl:when test="w:rPr">
  930.                                 <xsl:variable name="position">
  931.                                     <xsl:number from="/w:wordDocument/w:body" level="any" count="w:rPr" format="1"/>
  932.                                 </xsl:variable>
  933.                                 <xsl:attribute name="text:style-name">T<xsl:value-of select="$position + 1"/>
  934.                                 </xsl:attribute>
  935.                             </xsl:when>
  936.                         </xsl:choose>
  937.                         <xsl:apply-templates select="w:t | w:pict | w:br | w:instrText | w:fldChar | w:tab | w:footnote | w:endnote | aml:annotation | w:hlink | w:footnote | w:endnote"/>
  938.                     </text:span>
  939.                 </xsl:if>
  940.             </xsl:when>
  941.             <xsl:otherwise>
  942.                 <!-- add this condition to prevent from printing the value of DATE, TIME, PRINTDATE, CREATEDATE, SAVEDATE, PAGE, NUMPAGES, etc. fields in-between w:fldchar begin and w:fldchar end  G.Yang.-->
  943.                 <xsl:if test="not( preceding-sibling::w:r/w:instrText[substring(normalize-space(.),1,4) = 'DATE'  or substring(normalize-space(.),1,4) = 'TIME'  or  substring(normalize-space(.),1,9) = 'PRINTDATE'  or substring(normalize-space(.),1,10) = 'CREATEDATE'  or substring(normalize-space(.),1,8) = 'SAVEDATE' or substring(normalize-space(.),1,4) = 'PAGE' or substring(normalize-space(.),1,8) = 'NUMPAGES'  or substring(normalize-space(.),1,8) = 'NUMWORDS' or substring(normalize-space(.),1,8) = 'NUMCHARS' or substring(normalize-space(.),1,6) = 'REVNUM' or substring(normalize-space(.),1,7) = 'AUTONUM'  or  substring(normalize-space(.),1,10) = 'AUTONUMLGL' or substring(normalize-space(.),1,10) = 'AUTONUMOUT' or substring(normalize-space(.),1,3) = 'SEQ' or substring(normalize-space(.),1,6) = 'AUTHOR' or substring(normalize-space(.),1,5) = 'TITLE'  or substring(normalize-space(.),1,7) = 'SUBJECT'  or substring(normalize-space(.),1,8) = 'KEYWORDS' or substring(normalize-space(.),1,6) = 'FILLIN' or substring(normalize-space(.),1,11) = 'DOCPROPERTY' or substring(normalize-space(.),1,10) = 'MERGEFIELD' or substring(normalize-space(.),1,8) = 'MERGEREC' or substring(normalize-space(.),1,4) = 'NEXT' or substring( normalize-space(.),1,9) = 'HYPERLINK' or substring( normalize-space(.),1,3) = 'REF' ][1]  and (following-sibling::w:r/w:fldChar[@w:fldCharType='end'] or (  not(preceding-sibling::w:r/w:fldChar[@w:fldCharType='end'] ) and parent::w:p/following-sibling::w:p/w:r/w:fldChar[@w:fldCharType='end'])) )">
  944.                     <xsl:apply-templates select="w:t | w:pict | w:br | w:instrText | w:fldChar | w:tab | w:footnote | w:endnote | aml:annotation | w:hlink | w:footnote | w:endnote"/>
  945.                 </xsl:if>
  946.             </xsl:otherwise>
  947.         </xsl:choose>
  948.     </xsl:template>
  949.     <xsl:template match="aml:annotation">
  950.         <xsl:choose>
  951.             <xsl:when test="@w:type = 'Word.Bookmark.Start'">
  952.                 <text:bookmark-start text:name="{@w:name}"/>
  953.             </xsl:when>
  954.             <xsl:when test="@w:type = 'Word.Bookmark.End'">
  955.                 <xsl:variable name="id" select="@aml:id"/>
  956.                 <text:bookmark-end text:name="{preceding::aml:annotation[@aml:id = $id]/@w:name}"/>
  957.             </xsl:when>
  958.             <xsl:when test="@w:type = 'Word.Comment'">
  959.                 <office:annotation office:display="true">
  960.                     <dc:creator>
  961.                         <xsl:value-of select="@aml:author"/>
  962.                     </dc:creator>
  963.                     <dc:date>
  964.                         <xsl:value-of select="substring(@aml:createdate,1,10)"/>
  965.                     </dc:date>
  966.                     <xsl:apply-templates select="aml:content/w:p"/>
  967.                 </office:annotation>
  968.             </xsl:when>
  969.         </xsl:choose>
  970.     </xsl:template>
  971.     <xsl:template match="w:hlink">
  972.         <xsl:element name="text:a">
  973.             <xsl:attribute name="xlink:type">simple</xsl:attribute>
  974.             <xsl:choose>
  975.                 <xsl:when test="@w:dest and @w:bookmark">
  976.                     <xsl:attribute name="xlink:href">
  977.                         <xsl:value-of select="concat( @w:dest, concat('#', @w:bookmark) )"/>
  978.                     </xsl:attribute>
  979.                 </xsl:when>
  980.                 <xsl:when test="@w:dest">
  981.                     <xsl:attribute name="xlink:href">
  982.                         <xsl:value-of select="@w:dest"/>
  983.                     </xsl:attribute>
  984.                 </xsl:when>
  985.                 <xsl:when test="@w:bookmark">
  986.                     <xsl:attribute name="xlink:href">
  987.                         <xsl:value-of select="concat('#', @w:bookmark)"/>
  988.                     </xsl:attribute>
  989.                 </xsl:when>
  990.             </xsl:choose>
  991.             <xsl:if test="@w:target">
  992.                 <xsl:attribute name="office:target-frame-name">
  993.                     <xsl:value-of select="@w:target"/>
  994.                 </xsl:attribute>
  995.             </xsl:if>
  996.             <xsl:apply-templates select="w:r | w:fldSimple | w:hlink"/>
  997.         </xsl:element>
  998.     </xsl:template>
  999.     <xsl:template match="w:t">
  1000.         <xsl:choose>
  1001.             <xsl:when test="string(.) = ' ' ">
  1002.                 <xsl:element name="text:s"/>
  1003.             </xsl:when>
  1004.             <xsl:when test="contains(.,'  ')">
  1005.                 <xsl:call-template name="replace-spaces">
  1006.                     <xsl:with-param name="curr-string" select="."/>
  1007.                 </xsl:call-template>
  1008.             </xsl:when>
  1009.             <xsl:otherwise>
  1010.                 <xsl:value-of select="."/>
  1011.             </xsl:otherwise>
  1012.         </xsl:choose>
  1013.     </xsl:template>
  1014.     <xsl:template name="replace-spaces">
  1015.         <xsl:param name="curr-string"/>
  1016.         <xsl:if test="contains($curr-string,'  ')">
  1017.             <xsl:value-of select="substring-before($curr-string,'  ')"/>
  1018.             <text:s text:c="2"/>
  1019.             <xsl:variable name="next-string" select="substring-after($curr-string,'  ')"/>
  1020.             <xsl:choose>
  1021.                 <xsl:when test="contains($next-string, '  ')">
  1022.                     <xsl:call-template name="replace-spaces">
  1023.                         <xsl:with-param name="curr-string" select="$next-string"/>
  1024.                     </xsl:call-template>
  1025.                 </xsl:when>
  1026.                 <xsl:otherwise>
  1027.                     <xsl:value-of select="$next-string"/>
  1028.                 </xsl:otherwise>
  1029.             </xsl:choose>
  1030.         </xsl:if>
  1031.     </xsl:template>
  1032.     <xsl:template match="w:tab">
  1033.         <xsl:element name="text:tab"/>
  1034.     </xsl:template>
  1035.     <xsl:template match="w:br">
  1036.         <xsl:if test="@w:type='text-wrapping' or not(@w:type)">
  1037.             <text:line-break/>
  1038.         </xsl:if>
  1039.     </xsl:template>
  1040.     <xsl:template match="w:footnote">
  1041.         <xsl:variable name="footnote-position">
  1042.             <xsl:number from="/w:wordDocument/w:body" count="w:footnote" level="any"/>
  1043.         </xsl:variable>
  1044.         <text:note text:note-class="footnote" text:id="ftn{$footnote-position}">
  1045.             <text:note-citation/>
  1046.             <text:note-body>
  1047.                 <xsl:apply-templates select="w:p | w:tbl"/>
  1048.             </text:note-body>
  1049.         </text:note>
  1050.     </xsl:template>
  1051.     <xsl:template match="w:endnote">
  1052.         <xsl:variable name="endnote-position">
  1053.             <xsl:number from="/w:wordDocument/w:body" count="w:endnote" level="any" format="1"/>
  1054.         </xsl:variable>
  1055.         <text:endnote text:id="edn{$endnote-position}">
  1056.             <text:endnote-body>
  1057.                 <xsl:apply-templates select="w:p | w:tbl"/>
  1058.             </text:endnote-body>
  1059.         </text:endnote>
  1060.     </xsl:template>
  1061. </xsl:stylesheet>
  1062.